package com.itheima.visitor;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import java.util.HashMap;
import java.util.Map;

public class CommonMethodVisitor extends MethodVisitor {

    public enum Mark {
        P0(1),
        P1(2),
        P2(4),
        P3(8),
        P4(16),
        P5(32),
        P6(64),
        P7(128),
        P8(256),
        P9(512),
        P10(1024);

        private final int mask;
        Mark(int mask) {
            this.mask = mask;
        }

        public int getMask() {
            return mask;
        }
    }

    private int markFlag = 0;
    private Mark[] achieveMarks = new Mark[0];
    
    protected CommonMethodVisitor(Mark... achieveMarks) {
        super(Opcodes.ASM9);
        this.achieveMarks = achieveMarks;
    }

    public void mark(Mark mark) {
        this.markFlag |= mark.mask;
    }
    
    public boolean hasTarget() {
        int achieveFlag = 0;
        for (Mark mark : achieveMarks) {
            achieveFlag |= mark.mask;
        }
        return markFlag == achieveFlag;
    }
}
